﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
using System.Web.Mvc;
using Newtonsoft.Json;
using System.Web.Script.Serialization;
using myAutoExcuteJobService.Tools;

namespace mybolg.Controllers.Test
{
    public class TestController : Controller
    {
        public class jsd_req
        {
            public Base @base;
            public ReqDataInfo reqDataInfo;

            public jsd_req()
            {
                this.@base = new Base();
                this.reqDataInfo = new ReqDataInfo();
            }


            public class Base
            {
                public string boolSuccess;
                public string datetime;
                public string encryptflag;
                public string guid;
                public string zipflag;
                public Base()
                {
                    this.boolSuccess = "0";
                    this.datetime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    this.encryptflag = "1";
                    this.guid = Guid.NewGuid().ToString();
                    this.zipflag = "1";
                }
            }

            public class ReqDataInfo
            {
                public QueryInfo queryInfo;
                public UpdTimeSeqment updTimeSeqment;
                public ReqDataInfo()
                {
                    this.queryInfo = null;
                    this.updTimeSeqment = new UpdTimeSeqment();
                }

            }


            public class QueryInfo
            {
                public string contractId;
                public QueryInfo() { this.contractId = "33"; }

            }
            public class UpdTimeSeqment
            {

                public string endTime;
                public string startTime;
                public UpdTimeSeqment()
                {
                    this.endTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
                    this.startTime = "1990-01-01 12:01:01";
                }
            }

        }
        public class jsd_resp
        {
            public RespData respData;
            public Base @base;
            public ReqDataInfo reqDataInfo;
            public jsd_resp() { this.respData = new RespData(); }
    public class RespData
    {
        public List<Contract> contractList;
      
        public class Contract
        {
            public string workstata;
            public string company;
            public string quitTime;
            public string cellphone;
            public string ourAge;
            public string employmentNature;
            public string oneGradeDpt;
            public string pstName;
            public string entryDate;
            public string expectedPositive;
            public string terminationOfContrac;
            public string idCard;
            public string contractCode;
            public string employeeNumber;
            public string name;
            public string isDelete;
            public string contractId;
        }
     

    }
            public class Base
            {
                public string error;
                public string zipflag;
                public string refer;
                public string encryptflag;
                public string guid;
                public string boolSuccess;
                public string datetime;
            }

            public class ReqDataInfo
            {
                public QueryInfo queryInfo;
                public UpdTimeSeqment updTimeSeqment;
                public ReqDataInfo()
                {
                    this.queryInfo = new QueryInfo();
                    this.updTimeSeqment = new UpdTimeSeqment();
                }
                public class QueryInfo
                {
                    public string contractId;
                    public string idCard;
                    public string name;
                    public QueryInfo()
                    {
                        this.contractId = "";
                        this.idCard = "";
                        this.name = "";
                    }

                }
                public class UpdTimeSeqment
                {

                    public string endTime;
                    public string startTime;
                    public UpdTimeSeqment() { this.endTime = ""; this.startTime = ""; }
                }

            }
        }


        //
        // GET: /Test/

        public ActionResult Index()
        {
            return View();
        }
        public ActionResult daojishi() { return View(); }
        public ActionResult View1()
        {
            string jsonData = "{\"base\":{\"boolSuccess\":\"0\",\"datetime\":\"2017 - 08 - 24 13:50:52\",\"encryptflag\":\"0\",\"guid\":\"edoc2test1\",\"zipflag\":\"0\"},\"reqDataInfo\":{\"queryInfo\":{\"contractId\":33},\"updTimeSeqment\":{\"endTime\":\"2017 - 08 - 24 13:50:52\",\"startTime\":\"2015 - 08 - 24 13:50:52\"}}}";
            jsd_req jreq = JsonHelper.DeserializeJsonToObject<jsd_req>(jsonData);
            jsd_req jj = new jsd_req();
            string url = "http://t.koolearn.com/api/netContracts";
            PostData(url, JsonHelper.SerializeObject(jj));

            return View();
        }
        public JsonResult pachong(string jsonData)
        {
            //string jsonData = "{\"base\":{\"boolSuccess\":\"0\",\"datetime\":\"2017 - 08 - 24 13:50:52\",\"encryptflag\":\"0\",\"guid\":\"edoc2test1\",\"zipflag\":\"0\"},\"reqDataInfo\":{\"queryInfo\":{\"contractId\":33},\"updTimeSeqment\":{\"endTime\":\"2017 - 08 - 24 13:50:52\",\"startTime\":\"2015 - 08 - 24 13:50:52\"}}}";
            
            string url = "http://t.koolearn.com/api/netContracts";
            string aa = PostData(url, jsonData);
            return Json(aa,JsonRequestBehavior.AllowGet);
        }
        public ActionResult xlx()
        {



            return View();
        }


        private string PostData(string url, string postData)
        {
            ASCIIEncoding encoding = new ASCIIEncoding();
            byte[] data = encoding.GetBytes(postData);
            HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create(url);
            myRequest.ContentType = "application/json";
            myRequest.Accept = "*/*"; 
            myRequest.Method = "POST";
          //  myRequest.ContentType = "application/x-www-form-urlencoded";
            myRequest.ContentLength = data.Length;
            Stream newStream = myRequest.GetRequestStream();

            newStream.Write(data, 0, data.Length);
            newStream.Close();

            HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
            StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.UTF8);
            string content = reader.ReadToEnd();
            reader.Close();
            jsd_resp jsr=JsonHelper.DeserializeJsonToObject<jsd_resp>(content);
            return content;





    





        }











    }


}